package com.jg.utils.reflex.classes;

import com.jg.utils.reflex.en.User;
import com.jg.utils.reflex.utils.MethodUtils;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Method;

public class MethodTest {



    @Test
    public void testMethod() throws  Exception{
        Class<User> userClass = User.class;
        User user = new User("张三",23,"233");
        Method method = userClass.getDeclaredMethod("getIdNumber");
        method.setAccessible(true);
        method.invoke(user);
        Object value = method.invoke(user);
        System.out.println(value);

        Method setIdNumber = userClass.getDeclaredMethod("setIdNumber", String.class);
        setIdNumber.setAccessible(true);
        //invoke方法，执行指定对象的该方法，差数从第二个开始，是该方法的差数值
        setIdNumber.invoke(user,"5555");
        System.out.println(user);

    }
    @Test
    public void testMethodUtils(){
        User user = new User("张三",23,"233");
        Object result = MethodUtils.invokeMethod(user,"setName","cccc");

        System.out.println(user);
    }


}
